package com.example.proxy.cglib;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.logging.Logger;


public class ProxyFactory implements MethodInterceptor {
	public   Logger log = Logger.getLogger(this.getClass().getName());

	// ά��Ŀ�����
	private Object target;

	public ProxyFactory(Object target) {
		this.target = target;
	}

	/**
	 * ��Ŀ����󴴽�һ���������
	 * @return
	 */
	public Object getProxyInstance() {
		// TODO Auto-generated method stub
		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(target.getClass());
		enhancer.setCallback(this);
		return enhancer.create();
	}
	
 	public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
		// TODO Auto-generated method stub
		    log.info("cglib�ӻ�Ͳ");
			Object invoke = method.invoke(target, args);
			log.info("cglib�黹��Ͳ");
		return invoke;
	}

}
